Repository navigation
cacheable-request - fix: pass the response status to the cache policy - #1757
Merged
Merged
Conversation
http-cache-semantics reads the status code from `response.status`. A Node IncomingMessage has only `statusCode`, so the policy used 200 for each new response. Set `status` from `statusCode` before the policy is created, as the revalidation path does. This stops the cache from storing a 206 response to a range request and error responses such as 503 that have heuristic freshness.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1757 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 3620 3621 +1
Branches 824 824
=========================================
+ Hits 3620 3621 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Owner
|
@RClaudiuM - thanks. We shoulf have this released in a couple of weeks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.
Fixes #1755
Problem
cacheable-requestcreates the cache policy withnew CachePolicy(options_, response, options_). Theresponseis a NodeIncomingMessage.http-cache-semanticsreads the status code fromresponse.status, but anIncomingMessagehas onlystatusCode. Thus the policy used status 200 for each new response.Because of this, the cache did these things:
206 Partial Contentresponse to aRangerequest under the plain URL. A later request withoutRangegot the partial body from the cache.503with aLast-Modifiedheader (heuristic freshness), and returned them from the cache.Change
Set
response.status = response.statusCodebeforenew CachePolicy(...). The revalidation path already does this beforerevalidatedPolicy(...).Verification
pnpm test:ciinpackages/cacheable-request: Biome check passes, 70 tests pass, 100% statements and lines.pnpm buildinpackages/cacheable-requestpasses.A 206 response to a range request is not served for a full request: expected200, received206(from the cache).Error responses with heuristic freshness are not cached: expected cache size0, received1.Test audit (new tests only, no tests changed or deleted):
A 206 response to a range request is not served for a full requestRangerequest or gets a 206 response.request()API and a test server route.Error responses with heuristic freshness are not cachedLast-Modifiedis not stored.checks status codes when comparing cache & responseuses a 502 response without validators or freshness headers, so it passes with and without the fix.request()API and a test server route.